package com.yhos.platform.oopston.core.importselector;

import com.yhos.platform.oopston.core.annotation.AspectStarter;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

public class AspectImportSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        Map<String, Object> valueMap = annotationMetadata.getAnnotationAttributes(AspectStarter.class.getName());
        if (valueMap != null && valueMap.size() > 0) {
            for (Map.Entry<String, Object> entry : annotationMetadata.getAnnotationAttributes(AspectStarter.class.getName()).entrySet()) {
                Class[] classes = (Class[]) entry.getValue();
                String[] importClasses = new String[classes.length];
                for (int i = 0; i < classes.length; i++) {
                    importClasses[i] = classes[i].getName();
                }
                return importClasses;
            }
        }
        return new String[0];
    }

}
